package com.gxc.mall.user.repository;

import com.gxc.mall.user.entity.UserEntity;
import org.apache.catalina.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author GongXincheng
 * @since 2019-09-07 17:47
 */
public interface UserRepository extends JpaRepository<UserEntity, Integer>, JpaSpecificationExecutor<UserEntity> {

    /**
     * 根据用户名和密码查询.
     *
     * @param username 用户名
     * @param password 密码
     * @return 用户信息
     */
    UserEntity findByUsernameAndPassword(String username, String password);

    @Transactional(rollbackOn = Exception.class)
    @Modifying
    @Query(value = "update t_user set username = :username where id = :id", nativeQuery = true)
    void updateUserTest(Integer id, String username);
}
